function main() {
    debugger;
    const self = this;
    const recFormPartEle = self.$$("form_part_gv7p8v");

    if (!recFormPartEle) return;

    const recId = recFormPartEle.$$("number_input_happ9m").$$getValue();
    const recNum = recFormPartEle.$$("text_input_1ay7ts").$$getValue();
    const matterId = self.$$("text_input_cqtz1h").$$getValue();
    const matterName = self.$$("text_input_gcj49c").$$getValue();

    if (!recId) {
        self.$message.warning("请先保存案件信息");
        return true;
    }

    let itemData = window.selectMatter;
    if (!itemData || itemData.length === 0)  {
        self.$message.warning("请选择相关依据！");
        return true;
    }
    itemData.forEach(item => {
        item.recId = recId;
        item.recNum = recNum;
        item.matterId = matterId;
        item.matterName = matterName;
        item.lawCode = item.law_code;
        item.lawName = item.law_name;
        item.lawSetBasisTypeCode = item.law_set_basis_type_code;
        item.lawSetBasisTypeName = item.law_set_basis_type_name;
        item.lawItemId = item.law_item_id;
        item.lawItemCode = item.law_item_code;
        item.lawItemName = item.law_item_name;
        item.lawItemInfo = item.law_item_info;

    });

    deleteTable(recId).then(r => {
        itemData.forEach(itemData => {
            insertTable(itemData).then(r => {
                console.log(r);
            });
        });
    })


    itemData.forEach(itemData => {
        insertTable(itemData).then(r => {
            console.log(r);
        });
    });


    self.$message.success("保存成功");
    self.$router.push("/law/law_rec_matter");
    return true;
}

function deleteTable(recId) {
    return new Promise((resolve, reject) => {
        api.EXEC_FORMULA("DELETE('t_8aa3557055bc4550af180acceba1933a', QUERY_EQ('rec_id', " + recId + "), '')").then((res) => {
            debugger;
            console.log(res);
            resolve(res);
        });
    });

}

/**
 * 表名称：law_std_rec_matter_rel_set_basis
 * 实体标识：t_8aa3557055bc4550af180acceba1933a
 * @param itemData
 * @returns {Promise<unknown>}
 */
function insertTable(itemData) {
    const insertFields = [
        ['uid', 'UUID()'],
        ['rec_id', `'${itemData.recId}'`],
        ['rec_task_num', `'${itemData.recNum}'`],
        ['matter_id', `'${itemData.matterId}'`],
        ['rec_rel_matter_name', `'${itemData.matterName}'`],
        ['rec_rel_matter_id', `'${itemData.matterId}'`],
        ['law_code', `'${itemData.lawCode}'`],
        ['law_name', `'${itemData.lawName}'`],
        ['law_set_basis_type_code', `'${itemData.lawSetBasisTypeCode}'`],
        ['law_set_basis_type_name', `'${itemData.lawSetBasisTypeName}'`],
        ['law_item_id', `'${itemData.lawItemId}'`],
        ['law_item_code', `'${itemData.lawItemCode}'`],
        ['law_item_name', `'${itemData.lawItemName}'`],
        ['law_item_info', `'${itemData.lawItemInfo}'`],
        ['opt_type', `'I'`],
        ['create_time', 'NOW()'],
        ['update_time', 'NOW()']
    ];

    const formattedFields = insertFields.map(([key, value]) => {
        return `'${key}',${value}`;
    });

    const law_std_rec_matter_rel_set_basis = "t_8aa3557055bc4550af180acceba1933a";
    const insertSql = `INSERT('${law_std_rec_matter_rel_set_basis}', [${formattedFields.join(',')}])`;
    console.log(insertSql);
    return new Promise((resolve, reject) => {
        api.EXEC_FORMULA(insertSql).then(res => {
            resolve(res);
        })
    })

}



